package com.starview.star.code.repository;

import java.util.Map.Entry;

import com.starview.platform.resource.catalog.CatalogException;

public interface CodeCatalog extends CodeTree, Iterable<Entry<String, CodeTree>>
{
  public static final String EXTENSION = "code";

  /**
   * Add a new code entry to the code catalog
   * 
   * @param path
   *          a slash separated class name.
   * @param code
   * @throws CatalogException
   */
  void addCodeEntry(String path, CodeTree code) throws RepositoryException;

  /**
   * Hierarchical nodes can resolve paths.
   * 
   * @param path
   *          a slash-separated string of path segments. The first segment is the name of a child
   *          tree of this CodeCatalog.
   * @param extension
   *          the file extension to use when looking for this resource as a file
   * @return a CodeTree that corresponds to the requested sub-tree. Returns null if not present.
   */
  CodeTree resolve(String path, String extension) throws RepositoryException;

  /**
   * Create a sub-catalog by extending the path of this CodeCatalog based on new path.
   * 
   * @param path
   * @return a new code catalog rooted at the new path
   * @throws RepositoryException
   */
  CodeTree fork(String path) throws RepositoryException;

  /**
   * Check to see if an entry exists for a given path
   * 
   * @param path
   * @return
   */
  boolean isPresent(String path);

  /**
   * merge a code catalog into this one
   * 
   * @param other
   */
  void mergeEntries(CodeCatalog other) throws RepositoryException;

}
